package com.dsh.subscribe.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.dsh.subscribe.dao.HealthOtherCareProgramDao;
import com.dsh.subscribe.entity.HealthCareProgram;
import com.dsh.subscribe.entity.vo.HealthCareProgramVo;
import com.dsh.subscribe.entity.vo.HealthType;
import com.dsh.subscribe.entity.vo.PhysiotherapyCountVo;
import com.dsh.subscribe.entity.vo.SonTypeVo;
import com.dsh.subscribe.service.HealthOtherCareProgramService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class HealthOtherCareProgramServiceImpl implements HealthOtherCareProgramService {
    @Autowired
    HealthOtherCareProgramDao healthOtherCareProgramDao;

    @Override
    public HealthCareProgramVo queryById(Integer id) {
        HealthCareProgramVo healthCareProgramVo = healthOtherCareProgramDao.queryById(id);
        return healthCareProgramVo;
    }

    @Override
    public PageInfo<HealthCareProgram> queryAllByLimit(String projectName, String typeName, int limit, int page) {
        PageHelper.startPage(page,limit);
        if ((projectName == null) && (typeName == null)) {
            List<HealthCareProgram> healthCareProgram = healthOtherCareProgramDao.queryAllByLimit();
            return new PageInfo<>(healthCareProgram);
        }
        else {
            List<HealthCareProgram> healthCarePrograms = healthOtherCareProgramDao.queryAllByLimitM(projectName, typeName);
            return new PageInfo<>(healthCarePrograms);
        }
    }

    @Override
    public int update(HealthCareProgramVo healthCareProgramVo) {
        healthCareProgramVo.setShopName(JSONObject.toJSONString(healthCareProgramVo.getShopNames()));
        int update = healthOtherCareProgramDao.update(healthCareProgramVo);
        return update;
    }

    @Override
    public boolean deleteById(Integer id) {
        return false;
    }

    @Override
    public int updateStatus(int id) {
        int i = healthOtherCareProgramDao.updateStatus(id);
        return i;
    }

    @Override
    public List<HealthType> selectAllType() {
        List<HealthType> healthTypes = healthOtherCareProgramDao.selectAllType();
        return healthTypes;
    }

    @Override
    public int insertProgram(HealthCareProgramVo healthCareProgramVo) {
        healthCareProgramVo.setShopName((JSONObject.toJSONString(healthCareProgramVo.getShopNames())));
        int i = healthOtherCareProgramDao.insertProgram(healthCareProgramVo);
        return i;
    }

    @Override
    public PhysiotherapyCountVo selectPhysiotherapyCount() {
        PhysiotherapyCountVo physiotherapyCountVo = healthOtherCareProgramDao.selectPhysiotherapyCount();
        return physiotherapyCountVo;
    }

    @Override
    public int insertSonType(SonTypeVo sonTypeVo) {
        int i = healthOtherCareProgramDao.updateSonType(sonTypeVo);
        return i;
    }

    @Override
    public int updateSonType(SonTypeVo sonTypeVo) {
        int i = healthOtherCareProgramDao.updateSonType(sonTypeVo);
        return i;
    }

    @Override
    public PhysiotherapyCountVo selectSum() {
        PhysiotherapyCountVo physiotherapyCountVo = healthOtherCareProgramDao.selectSum();
        return physiotherapyCountVo;
    }
}
